import permissionService from "../serivce/permissionService";
const state = {
  roleList: [],
  memberList: [],
};

const getters = {};

const mutations = {
  SET_ROLE_LIST(state, data) {
    state.roleList = data;
  },
  SET_MEMBER_LIST(state, data) {
    state.memberList = data;
  },
};

const actions = {
  async GetMenu({ commit }) {
    try {
      let result = await permissionService.GetMenu();
      console.log(result);
      if (result.data.code == 200) {
        return result.data.data;
      }
    } catch (error) {
      console.log(error);
    }
  },

  async RoleList({ commit }) {
    try {
      let result = await permissionService.RoleList();
      console.log(result);
      commit("SET_ROLE_LIST", result.data.data);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async AddRole({ commit }, data) {
    try {
      let result = await permissionService.AddRole(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async UpdateRole({ commit }, data) {
    console.log(data);
    try {
      let result = await permissionService.UpdateRole(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async UpdateRoles({ commit }, data) {
    console.log(data);
    try {
      let result = await permissionService.UpdateRoles(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async GetRole({ commit }, id) {
    try {
      let result = await permissionService.GetRole(id);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async DelRole({ commit }, idArr) {
    try {
      let result = await permissionService.DelRole(idArr);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async MemberList({ commit }, data) {
    try {
      let result = await permissionService.MemberList(data);
      console.log(result);
      commit("SET_MEMBER_LIST", result.data.data);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async AddMember({ commit }, data) {
    try {
      let result = await permissionService.AddMember(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async Register({ commit }, data) {
    try {
      let result = await permissionService.Register(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async UpdateMember({ commit }, data) {
    console.log(data);
    try {
      let result = await permissionService.UpdateMember(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async GetUserById({ commit }, id) {
    console.log(id);
    try {
      let result = await permissionService.GetUserById(id);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async DelMember({ commit }, idArr) {
    try {
      let result = await permissionService.DelMember(idArr);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async DelMemberRole({ commit }, data) {
    try {
      let result = await permissionService.DelMemberRole(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async OperateLogList({ commit }, data) {
    try {
      let result = await permissionService.OperateLogList(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async GetUserRoles({ commit }, data) {
    try {
      let result = await permissionService.GetUserRoles(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async SetUserRoles({ commit }, data) {
    try {
      let result = await permissionService.SetUserRoles(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },

  async DelOperationLog({ commit }, data) {
    try {
      let result = await permissionService.DelOperationLog(data);
      console.log(result);
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },
  
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
